"""
encoding = 'utf-8'
@author : ffine
@time   : 2022-05-04  20:05
@IDEA   : PyCharm
@goal   : 特殊成员和魔法方法
"""
from ep07.DemoClass import People
# __init__() 构造方法
people = People("ffine", 20)

# __del__() 析构方法
# del people

# __doc__ 文档字符串
# __module__ 模块名
# __class__ 类名
print(people.__doc__)   # 这是一个人的类
print(people.__module__)    # ep07.DemoClass
print(people.__class__)  # <class 'ep07.DemoClass.People'>

# __call__() 调用方法
print(callable(people))  # True
res = people("hello", "world", "!")
print(res)

# __dict__() 属性字典
print("__dict__:", people.__dict__)  # 私有属性也可以访问

# __str__() 字符串方法
print("__str__ :", str(people))

# __len__() 长度
print("__len__ :", len(people))

# print(people.__next__())
# __iter__() 迭代器,使得类可以被迭代
for i in people:
	print(f"people: {people.name} is {i} {'years' if i > 1 else 'year'} old")

print(f"{'item':=^50}")
# __getitem__(), 可以使用索引访问类的属性; __setitem__(), 可以使用索引设置类的属性; __delitem__(), 可以使用索引删除类的属性
dic = {"name": "ffine", "age": 20, "addr": "Jx"}
print(dic["name"])
dic["name"] = "ffine2"
print(dic["name"])

print(people["name"])
people["name"] = "ffine3"
print(people["name"])
people["addr"] = "Jx2"
print(people.__dict__)
del people["addr"]
print(people.__dict__)

print(f"{'计算':=^50}")

# __add__() 加法; __sub__() 减法; __mul__() 乘法; __truediv__() 除法; __floordiv__() 取整除法; __mod__() 求余; __pow__() 求幂
x, y = 1, 2
print(x+y)
people1 = People("fanheying", 24)
people2 = People("sunan", 21)
print(people1 + people2)
